/**
 * Created by Administrator on 2017/7/27.
 */
angular.module('service.common',['ngResource'])

    .service("ActivityService",["$resource",function ($resource) {

        /**添加活动
         * 
         * require  active对象（除activeId）
         * 
         * return   active对象(创建出的)
         * */
        this.addActivity=function(activity,sfun,efun){
            var resource=$resource(Activity_url);
            return resource.save(activity,sfun,efun)
        };

        /**根据activeId删除对应的活动
         *
         *require   activeId
         *
         *return    active(被删除的)
         */
        this.deleteActivity=function(activeId,sfun,efun){
            var resource=$resource(Activity_url+'/:activeId');
            return resource.remove({activeId:activeId},sfun,efun)
        };

        /*根据activeId更新对应的活动

         * require   含activeId的active对象(不要求完整)
         *
         * return    active对象(更新后)
         * */
        this.updateActivity=function (activity,sfun,efun) {
            var resource=$resource(Activity_url+'/:activeId');
            return resource.save({activeId:activity.activeId},activity,sfun,efun)
        };

        /**根据activeId查找对应的活动
        * 
        * require    activeId
        * 
        * return     active对象
        */
        this.getActivity=function (activeId,sfun,efun) {
            var resource=$resource(Activity_url+'/:activeId');
            return resource.get({activeId:activeId},sfun,efun)
        };

        /**根据originatorId(选填)，activeState(选填)，pageNum(选填)，获得活动列表对象
        *  
        *require    originatorId(选)
        *           activeState(选)
        *           pageNum(选)
        *           
        *return     activityListPage
        * */
        this.getActivityList=function(query_terms,sfun,efun){
            var resource=$resource(Activity_url);
            return resource.get(query_terms,sfun,efun)
        };

        /*根据用户参与状态获得活动列表对象
        
        * require   userId
        *           enrollState(选)
        *           pageNum(选)
        *           
        * return    activityListPage
        * */
        this.getActivityListByUserEnrollState=function (query_terms,sfun,efun) {
            var resource=$resource(Activity_url+"/byUserEnrollState/:userId");
            return resource.get({userId:query_terms.userId,enrollState:query_terms.enrollState,pageNum:query_terms.pageNum},sfun,efun)
        }
    }])

    .service("OriginatorService",["$resource",function ($resource) {
        /**添加组织者
         * 
         * require  originator对象（除originatorId）
         * 
         * return   originator对象(创建出的)
         * */
        this.addOriginator=function (Originator,sfun,efun) {
            var resource=$resource(originator_url);
            return resource.save(Originator,sfun,efun)
        };
        
        /*根据组织者ID删除组织者
        
        * require   originatorId
        * 
        * return    originator对象(删除后)
        * */
        this.deleteOriginator=function (OriginatorId,sfun,efun) {
            var resource=$resource(originator_url+'/:originatorId');
            return resource.remove({originatorId:OriginatorId},sfun,efun)
        };
        
        /*根据组织者ID更新组织者信息
        
        * require   Originator(含originatorId,不需完整对象)
        * 
        * return    originator(更新后)
        * */
        this.updateOriginator=function (Originator,sfun,efun) {
            var resource=$resource(originator_url+'/:originatorId');
            return resource.save({originatorId:Originator.originatorId},Originator,sfun,efun)
        };
        
        /*根据组织者ID获取组织者信息
        
        * require   originatorId
        * 
        * return    originator
        * */
        this.getOriginator=function(originatorId,sfun,efun){
            var resource=$resource(originator_url+'/:originatorId');
            return resource.get({originatorId:originatorId},sfun,efun)
        };
        /*获取组织者列表对象(可根据组织者状态过滤)
        
        * require   originatorState(选)
        *           pageNum(选)
        *           
        * return    originatorListPage
        * */
        this.getOriginatorListByState=function(query_terms,sfun,efun){
            var resource=$resource(originator_url);
            return resource.get(query_terms,sfun,efun)
        };
    }])

    .service("ActiveEnrollService",['$resource',function ($resource) {
        /*创建活动报名条目
        *
        * require   activeEnroll
        *
        * return    activeEnroll(创建成功后的)
        * */
        this.addActiveEnroll=function(activeEnroll,sfun,efun){
            var resource=$resource(Activity_enroll_url);
            return resource.save(activeEnroll,sfun,efun)
        };

        /*根据活动ID和用户ID删除活动报名条目
        *
        * require   activeId
        *           userId
        *
        * return    activeEnroll
        * */
        this.deleteActiveEnroll=function (query_terms,sfun,efun) {
            var resource=$resource(Activity_enroll_url+'/:activeId/:userId');
            return resource.remove({activeId:query_terms.activeId,userId:query_terms.userId},sfun,efun)
        };

        /*根据活动ID和用户ID更新活动报名条目
        *
        * require   activeEnroll(含activeId、userId)
        *
        * return    activeEnroll(更新后的)
        * */
        this.updateActiveEnroll=function (activeEnroll,sfun,efun) {
            var resource=$resource(Activity_enroll_url+'/:activeId/:userId');
            return resource.save({activeId:activeEnroll.activeId,userId:activeEnroll.userId},activeEnroll,sfun,efun)
        };

        /*根据活动ID和用户ID查询活动报名条目
        *
        * require   activeId
        *           userId
        *
        * return    activeEnroll
        * */
        this.getActiveEnroll=function (query_terms,sfun,efun) {
            var resource=$resource(Activity_enroll_url+'/:activeId/:userId');
            return resource.get(query_terms,sfun,efun)
        };

        /*获取活动报名列表
        *
        *  require  activeId或userId(选)
        *           state(选)
        *           pageNum(选)
        *
        * return    activeEnrollListPage
        * */
        this.getActiveEnrollList=function (query_terms,sfun,efun) {
            if (!query_terms.activeId&&!query_terms.userId){
                var resource=$resource(Activity_enroll_url);
                return resource.get(sfun,efun)
            }else
            if (query_terms.activeId){
                var resource=$resource(Activity_enroll_url+'/ByActiveId/:activeId');
                return resource.get(query_terms,sfun,efun)
            }else
            if (query_terms.userId){
                var resource=$resource(Activity_enroll_url+'/ByUserId/:userId');
                return resource.get(query_terms,sfun,efun)
            }
        };
    }]);
